{% extends 'home/home.html' %}

{% block db_book %}
    <!-- 标题 -->
    <div class="book-head">
        <div class="auth-bg bg pull-left"></div>
        <span class="pull-left bg-text">{{ auth_obj.auth_name }}</span>
    </div>
    <!-- 遍历图书 -->
    <table class="table table-striped">
        <thead>
        <tr class="info text-muted" align="center">
            <th width="50" style="text-align: center">编号</th>
            <th width="250" style="text-align: center">书名</th>
            <th width="200" style="text-align: center">出版社</th>
            <th width="200" style="text-align: center">作者</th>
            <th></th>
        </tr>
        </thead>
        <tbody>
        {% for book in book_obj %}
            <tr height="50" align="center">
                <td class="text-muted small">{{ forloop.counter }}</td>
                <td class="small">{{ book.book_name }}</td>
                <!-- 出版社超链接 -->
                <td class="small">
                    <a href="/app_home/{{ book.pub_id }}/pub_info/">{{ book.pub.pub_name }}</a>
                </td>
                <!-- 作者超链接 -->
                <td class="small">{% for auth in book.auth.all %}
                    <a href="/app_home/{{ auth.pk }}/auth_info/">{{ auth.auth_name }}</a>
                {% endfor %}
                </td>
                <td>
                    <!-- 删除 -->
                    <a href="/app_home/{{ book.pk }}/delete_book" class="btn btn-info btn-sm pull-right iconfont">&#xe88a;</a>
                    <span class="btn btn-info btn-sm pull-left iconfont" style="margin-left: 20px" data-toggle="modal"
                          data-target="#modal{{ book.pk }}">&#xe606;</span>
                    <!-- 修改：模态框 -->
                    <div class="modal fade" id="modal{{ book.pk }}" tabindex="-1" role="dialog"
                         aria-labelledby="mySmallModalLabel">
                        <div class="modal-dialog modal-sm" role="document">
                            <div class="modal-content">
                                <form class="form-horizontal" action="" method="post">
                                    {% csrf_token %}
                                    <div class="form-group">
                                        <!-- 修改前 -->
                                        <div class="col-md-offset-1 col-md-10" style="margin-top: 30px">
                                            <input class="form-control" name="{{ book.pk }}book_name"
                                                   value={{ book.book_name }} disabled>
                                        </div>
                                        <!-- 作者 -->
                                        <div class="col-md-offset-1 col-md-10" style="margin-top: 30px">
                                            <div class="clearfix"
                                                 style="border: 1px solid #ccc; border-radius: 4px">
                                                {% for auth2 in auth_all_obj %}
                                                    <div class="pull-left small" style="padding: 10px">
                                                        <!-- 检测关联关系 -->
                                                        {% if auth2 in book.auth.all %}
                                                            <input type="checkbox" name="auth_id_list"
                                                                   value={{ auth2.pk }} checked>
                                                        {% else %}
                                                            <input type="checkbox" name="auth_id_list"
                                                                   value={{ auth2.pk }}>
                                                        {% endif %}

                                                        <span>{{ auth2.auth_name }}</span>
                                                    </div>
                                                {% endfor %}
                                            </div>
                                        </div>
                                        <!-- 出版社 -->
                                        <div class="col-md-offset-1 col-md-10" style="margin-top: 30px">
                                            <select name="pub_id" class="form-control">
                                                {% for pub in pub_obj %}
                                                    <!-- 检测关联关系 -->
                                                    {% if pub == book.pub %}
                                                        <option value={{ pub.pk }} selected>{{ pub.pub_name }}</option>
                                                    {% else %}
                                                        <option value={{ pub.pk }}>{{ pub.pub_name }}</option>
                                                    {% endif %}

                                                {% endfor %}
                                            </select>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <div class="col-md-offset-1 col-md-10" style="margin-bottom: 10px">
                                            <!-- home.js -->
                                            <span class="btn btn-info btn-block change_book">确认修改</span>
                                        </div>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                </td>
            </tr>
        {% endfor %}
        </tbody>
    </table>


{% endblock %}